package com.cgy.service.Impl;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.cgy.entity.ConsumeLogs;
import com.cgy.repository.ConsumeLogsRepository;
import com.cgy.service.ConsumeLogsService;
@Service
public class ConsumeLogsServiceImpl implements ConsumeLogsService {
@Autowired
private ConsumeLogsRepository consumeRepository;
	@Override
	public Page<ConsumeLogs> findAllConsumeLogs(ConsumeLogs c, Pageable pageable) {
		// TODO Auto-generated method stub
		return consumeRepository.findAll(get(c), pageable);
	}

	private Specification<ConsumeLogs> get(ConsumeLogs c) {
		// TODO Auto-generated method stub
		return new Specification<ConsumeLogs>() {

			@Override
			public Predicate toPredicate(Root<ConsumeLogs> root, CriteriaQuery<?> query,
					CriteriaBuilder criteriaBuilder) {
				// 创建动态sql
				Predicate predicate = criteriaBuilder.conjunction();
				List<Expression<Boolean>> exList = predicate.getExpressions();
				
				return predicate;
			}
		};
	}
	@Transactional
	@Override
	public ConsumeLogs addAndUpdateConsumeLogs(ConsumeLogs c) {
		// TODO Auto-generated method stub
		return consumeRepository.saveAndFlush(c);
	}
	@Transactional
	@Override
	public Integer deleteConsumeLogs(Integer lid) {
		// TODO Auto-generated method stub
		return consumeRepository.deleteConsumeLogs(lid);
	}

}
